/*
 * Copyright 2007 David R Kirkland 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");  
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

using System;
using System.Collections.Generic;
using System.Text;
using NetSpider.Retrieval;

namespace NetSpider.Retrieval
{
    public class FetchRequest : IFetchRequest
    {
        private string _uri;
        private string _uriSchema;

        private List<FetchRequest> _previousRequests;

        private DateTime _requestedTime;
        private DateTime _fetchScheduledFor;

        private bool _isReferral = false;
        private string _referredBy;

        public FetchRequest(string uri)
        {
            _uri = uri;
            _uriSchema = UriHelper.GetUriSchema(uri);
            _requestedTime = DateTime.Now;
            _fetchScheduledFor = DateTime.Now;
        }

        public FetchRequest(string uri, string referredBy)
        {
            _uri = uri;
            _referredBy = referredBy;
            _isReferral = true;
        }

        public FetchRequest(RetrievalResult result)
        {
            
        }

        //public FetchRequest(FetchResult result)
        //{
        //    _previousRequests.AddRange(result.Request.PreviousRequests);
        //    _previousRequests.Add(result.Request);
        //    _fetchRequestedAt = DateTime.Now;
        //    _fetchScheduledFor = result.Decision.ScheduleRetryFor;
        //    _uri = result.Request.Uri;
        //    _uriSchema = result.Request.UriSchema;
        //}

        public string Uri
        {
            get { return _uri; }
        }

        public string UriSchema
        {
            get { return _uriSchema; }
        }

        public DateTime NextFetchAttempt
        {
            get { return _fetchScheduledFor; }
        }

        public List<FetchRequest> PreviousRequests
        {
            get { return _previousRequests; }
        }

        public DateTime RequestTime
        {
            get { return _requestedTime; }
        }

        public bool IsReferral
        {
            get { return _isReferral; }
        }

        /// <summary>
        /// URI which is responsible for referral.
        /// </summary>
        public string ReferredBy
        {
            get { return _referredBy; }
        }

        public Uri RequestedUri
        {
            get { throw new NotImplementedException(); }
        }

        public void Update(IRetrievalResult result)
        {
            throw new NotImplementedException();
        }

        public IRetrievalResult[] GetRetrievalResults()
        {
            throw new NotImplementedException();
        }

        public bool IsReferred
        {
            get { throw new NotImplementedException(); }
        }

        public Uri ReferredByUri
        {
            get { throw new NotImplementedException(); }
        }
    }
}